package com.piggy.system.api.factory;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.domain.AjaxResult;
import com.piggy.system.api.RemoteConfigService;
import com.piggy.system.api.domain.SysConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 系统配置服务降级处理
 *
 * @author shark
 */
@Component
public class RemoteConfigFallbackFactory implements FallbackFactory<RemoteConfigService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteConfigFallbackFactory.class);

    @Override
    public RemoteConfigService create(Throwable throwable) {
        log.error("系统配置服务调用失败:{}", throwable.getMessage());
        return new RemoteConfigService()
        {

            @Override
            public R<SysConfig> getConfigByKey(String configKey, String source) {
                return R.fail("获取系统参数失败:" + throwable.getMessage());
            }

            @Override
            public R<String> selectConfigByKey(String configKey, String source) {
                return R.fail("获取系统参数失败:" + throwable.getMessage());
            }

            @Override
            public R<SysConfig> getConfigById(Long configId, String source) {
                return R.fail("获取系统参数失败:" + throwable.getMessage());
            }


            @Override
            public AjaxResult updateSendRule(String noticeCondition,String noticeDay,  String source) {
                return  AjaxResult.error("获取系统参数失败:" + throwable.getMessage());
            }


        };
    }
}
